#!/bin/bash

EPICS_PATH=/opt/epics

OS=$(cat /etc/*release | grep ^NAME | tr -d 'NAME="')
YUM_PACK_NAME="gcc gcc-c++ make kernel-devel perl"
DEB_PACK_NAME="build-essential perl"
if (echo $OS | grep CentOS) ; then
	echo "==============================================="
	echo "Installing packages $YUM_PACK_NAME on CentOS"
	yum install -y $YUM_PACK_NAME
	echo "==============================================="
elif (echo $OS | grep Ubuntu) ; then
	echo "==============================================="
	echo "Installing packages $DEB_PACK_NAME on Ubuntu"
	apt install -y $DEB_PACK_NAME
	echo "==============================================="
fi
chmod a+w -R /opt

if ! (cat /etc/profile | grep EPICS_BASE) ; then
	echo export EPICS_BASE=$EPICS_PATH/base-3.15.9 >> /etc/profile
	echo export PATH=\$PATH:$EPICS_PATH/base-3.15.9/bin/linux-x86_64 >> /etc/profile
	echo export EPICS_CA_ADDR_LIST=127.0.0.1 >> /etc/profile
	echo export EPICS_CA_AUTO_ADDR_LIST=no >> /etc/profile
fi

if ! (cat /etc/profile | grep PROCSERV_DIR) ; then
    	 echo export PROCSERV_DIR=/opt/procServ-2.8.0 >> /etc/profile
       echo export PATH=\$PATH:\$PROCSERV_DIR >> /etc/profile
fi
